package vim.meet.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class AroundAdviceExample {
	
	@Pointcut("execution(* cn.freemethod.aspect.target.BeforeTarget.around())")
	private void aroundPointcut(){}
	
	@Around("aroundPointcut()")
	public void around(ProceedingJoinPoint pjp)
	{
		Object proceed = null;
		long start = System.currentTimeMillis();
		try {
			proceed = pjp.proceed();
		} catch (Throwable e) {
			e.printStackTrace();
		}
		long end = System.currentTimeMillis();
		System.out.println("result:"+proceed+" cost:"+(end-start));
	}
	
	
	@Around("execution(* cn.freemethod.aspect.target.BeforeTarget.around(String)) && args(name)")
	public void aroundWithPara(ProceedingJoinPoint pjp,String name)
	{
		Object proceed = null;
		long start = System.currentTimeMillis();
		try {
			proceed = pjp.proceed();
		} catch (Throwable e) {
			e.printStackTrace();
		}
		long end = System.currentTimeMillis();
		System.out.println("result:"+proceed+" cost:"+(end-start));
		System.out.println(name);
	}

}
